package cn.ivbao.daos;

import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.engine.execution.SqlExecutor;
import com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient;

public abstract class BaseDao extends SqlMapClientDaoSupport{
	 private SqlExecutor sqlExecutor;
	 
	  public SqlExecutor getSqlExecutor() {
		return sqlExecutor;
	}

	public void setSqlExecutor(SqlExecutor sqlExecutor) {
		this.sqlExecutor = sqlExecutor;
	}
	
//	SqlMapClientTemplate sqlMapClientTemplate = getSqlMapClientTemplate();

	public void initialize() throws Exception
	  {
	    if (sqlExecutor != null)
	    {
	      SqlMapClient sqlMapClient = getSqlMapClientTemplate().getSqlMapClient();
	      if (sqlMapClient instanceof ExtendedSqlMapClient)
	      {
	        ReflectUtil.setFieldValue(((ExtendedSqlMapClient) sqlMapClient)
	            .getDelegate(), "sqlExecutor", SqlExecutor.class, sqlExecutor);
	      }
	    }
	  }

}
